"use strict";

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  let config = (exports = {});
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1620927537251_5175";

  config.cluster = {
    listen: {
      path: '',
      port: 7010,
      hostname: '127.0.0.1',
    }
  };

  // add your middleware config here
  config.middleware = ["errorHandler", "auth"];
  // 配置那些路由需要验证
  config.auth = {
    // ignore: ['/reg', '/login'],//不需要token验证的接口
    enable: true,
    match: [
      //需要token验证的接口
      "/logout",
      "/v1/**",
    ],
  };

  config.swaggerdoc = {
    dirScanner: "./app/controller", // 配置自动扫描的控制器路径
    // 接口文档的标题，描述或其它
    apiInfo: {
      title: "Render", // 接口文档的标题
      description: "swagger-ui for Render document.", // 接口文档描述
      version: "1.0.0", // 接口文档版本
    },
    schemes: ["http", "https"], // 配置支持的协议
    consumes: ["application/json"], // 指定处理请求的提交内容类型（Content-Type），例如application/json, text/html
    produces: ["application/json"], // 指定返回的内容类型，仅当request请求头中的(Accept)类型中包含该指定类型才返回
    securityDefinitions: {
      // basicAuth:{
      //   type:'basic'
      // }

      // 配置接口安全授权方式
      apikey: {
        type: "apiKey",
        name: "token",
        in: "header",
      },
      // oauth2: {
      //   type: 'oauth2',
      //   tokenUrl: 'http://petstore.swagger.io/oauth/dialog',
      //   flow: 'password',
      //   scopes: {
      //     'write:access_token': 'write access_token',
      //     'read:access_token': 'read access_token',
      //   },
      // },
    },
    enableSecurity: true, // 是否启用授权，默认 false（不启用）
    // enableValidate: true,    // 是否启用参数校验，默认 true（启用）
    routerMap: true, // 是否启用自动生成路由，默认 true (启用)
    enable: true, // 默认 true (启用)
  };

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  config.security = {
    // 关闭 csrf
    csrf: {
      enable: false,
    },
    // 跨域白名单
    // domainWhiteList: [ 'http://localhost:3000' ],
  };
  // 允许跨域的方法
  config.cors = {
    origin: "*",
    allowMethods: "GET, PUT, POST, DELETE, PATCH",
  };
  config.sequelize = {
    dialect: "mysql", // 数据库类型，支持 mysql,sqlite,mssql,pgsql,oracle
    host: "localhost", // 数据库服务器地址 http://localhost/
    port: 3306, // 数据库连接端口号
    database: "library", // 数据库名称
    username: "root", // 数据库登录用户名
    password: "123456", // 数据库登录密码
    // 中国时区
    timezone: "+08:00",
    define: {
      // 取消数据表名复数
      freezeTableName: true,
      // 自动写入时间戳 created_at updated_at deleted_at
      timestamps: true,
      // 是否逻辑删除
      paranoid: true,
      createdAt: "created_time",
      updatedAt: "updated_time",
      deletedAt: "deleted_time",
      // 所有驼峰命名格式化
      underscored: true,
    },
  };
  config.valparams = {
    locale: "zh-cn",
    throwError: true,
  };
  config.crypto = {
    secret: "qhdgw@45ncashdaksh2!#@3nxjdas*_672",
  };
  config.jwt = {
    secret: "qhdgw@45ncashdaksh2!#@3nxjdas*_672",
  };
  config.redis = {
    client: {
      port: 6379, // Redis port
      host: "localhost", // Redis host
      password: "",
      db: 4,
    },
  };
  config.multipart = {
    fileSize: "50mb",
    mode: "stream",
    fileExtensions: [
      ".xls",
      ".txt",
      ".jpg",
      ".JPG",
      ".png",
      ".PNG",
      ".gif",
      ".GIF",
      ".jpeg",
      ".JPEG",
    ],
  };

  // config.io = {
  //   init: { wsEngine: 'ws' },
  //   namespace: {
  //     "/": {
  //       connectionMiddleware: ["connection"],
  //       packetMiddleware: ["packet"],
  //     },
  //     "/chat": {
  //       connectionMiddleware: ["connection"],
  //       packetMiddleware: [],
  //     },
  //   },
  // };

  config.amqplib = {
      client: {
      // url: 
      connectOptions: {
        protocol: 'amqp',
        hostname: 'localhost',
        port: 5672,
        username: 'guest',
        password: 'guest',
        locale: 'en_US',
        frameMax: 0,
        heartbeat: 0,
        vhost: '/',
      },
      // socketOptions: {
      //   cert: certificateAsBuffer, // client cert
      //   key: privateKeyAsBuffer, // client key
      //   passphrase: 'MySecretPassword', // passphrase for key
      //   ca: [caCertAsBuffer], // array of trusted CA certs
      // },
    },
  };


 


  return {
    ...config,
    ...userConfig,
  };
};
